package org.yufan.controller.rpc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yufan.bean.Item;
import org.yufan.common.Result;
import org.yufan.common.ResultUtils;
import org.yufan.service.ItemService;
import org.yufan.utils.ResponseUtils;

@Controller
@RequestMapping("/rpc/item/")
public class ItemRpcController {

    private Logger LOGGER=LoggerFactory.getLogger(ItemRpcController.class);

    @Autowired
    private ItemService itemService;

    @RequestMapping(value = "{itemId}",method = RequestMethod.GET)
    public ResponseEntity<Result>  queryItem(@PathVariable("itemId")Long itemId){
        LOGGER.debug("查询的商品id为{}:",itemId);
        Item item = itemService.queryById(itemId);
        if(item==null){
            LOGGER.error("商品查询失败，查询的商品id为{}",itemId);
            return ResponseEntity.ok(ResultUtils.buildFail(101,"商品查询失败!"));
        }
        return ResponseEntity.ok(ResultUtils.buildSuccess(item));
    }



}
